package symbols;

/**
 * An entry for a simple symbol (a var) in the symbol table
 * 
 * @author marc
 *
 */
public class SLeftValue extends Symbol {
	private Object value = null;	// is set after object instantiation
	private boolean isSet = false;
	
	public SLeftValue(int type, String name) {
		super(type, name);
		
		/*
		 * Workaround to implement the new behaviour
		 * which is to initialize values by default.
		 */
		if(type == Type.NUM) 
			value = new Integer(0);
		else if(type == Type.STR)
			value = new String("\"\"");
		else if(type == Type.SET)
			value = new HLSet();
		else
			value = null;	
		
		isSet = true;
	}
	
	public Object clone() {
		SLeftValue newValue = new SLeftValue(type, name);
		newValue.setValue(value);
		return newValue;
	}
	
	public void setValue(Object value) {
		this.value = value;
		isSet = true;
	}
	
	public Object getValue() {
		return value;
	}
	
	public boolean isSet() {
		return isSet;
	}
	
	public String toString() {
		if(! isSet)
			return "Identifier of type " + Type.names[type];
		else
			return (value != null)?value.toString():"null"; 
	}
	
}
